from sqlalchemy import CHAR, ForeignKey
from sqlalchemy.orm import Mapped, mapped_column, relationship

from app.extensions import Base, INT_PK, STR_NOTNULL_20

class Student(Base):
    __tablename__= "students"
    id: Mapped[INT_PK] # 主键id
    name:Mapped[STR_NOTNULL_20]
    gender: Mapped[str] = mapped_column(CHAR(1), default="男", nullable=False)
    clas_id: Mapped[int] = mapped_column(ForeignKey('clases.id'), nullable=False)

    #关联属性
    clas: Mapped["Clas"] = relationship(back_populates="studentsList", lazy=False)
    def  __repr__(self):
       return f"<Student id:{self.id} name:{self.name} gender:{self.gender} clas: {self.clas}>"

if __name__ == '__main__':
    from app.models.Clas import Clas
    from app.extensions import engine
    Base.metadata.create_all(engine)

